<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" id="time-unit-select" />
		<input type="text" id="time-point-input" />
		<input type="text" id="repeat-frequency-input" />
		<input type="button" id="btn" value="点击" onclick="generateCronExpression()"/>
		<p id="result"></p>
	</body>
	
	<script>
	function generateCronExpression() {
  // 获取用户的选择
  let timeUnit = document.getElementById("time-unit-select").value;
  let timePoint = document.getElementById("time-point-input").value;
  let repeatFrequency = document.getElementById("repeat-frequency-input").value;
  
  // 根据用户选择生成Cron表达式
  let cronExp = "";
  if (timeUnit === "hourly") {
    cronExp = `0 ${timePoint} 0/${repeatFrequency} * * *`;
  } else if (timeUnit === "daily") {
    cronExp = `0 ${timePoint} * * * *`;
  } else if (timeUnit === "weekly") {
    cronExp = `0 ${timePoint} * * ${repeatFrequency} *`;
  } else if (timeUnit === "monthly") {
    cronExp = `0 ${timePoint} ${repeatFrequency} * * *`;
  }
  
  document.getElementById("result").innerHTML = cronExp;

}
generateCronExpression();


function getNextExecutionTime(cronExp) {
  let cronArr = cronExp.split(" ");
  let now = Date.now();
  
  // 解析分钟表达式
  let minuteExp = cronArr[0];
  let nextMinute = getNextValidValue(minuteExp, new Date(now).getMinutes());
  
  // 解析小时表达式
  let hourExp = cronArr[1];
  let nextHour = getNextValidValue(hourExp, new Date(now).getHours());
  
  // 解析日表达式
  let dayExp = cronArr[2];
  let nextDay = getNextValidValue(dayExp, new Date(now).getDate());
  
  // 解析月表达式
  let monthExp = cronArr[3];
  let nextMonth = getNextValidValue(monthExp, new Date(now).getMonth() + 1);
  
  // 解析星期表达式
  let weekExp = cronArr[4];
  let nextWeekDay = getNextValidValue(weekExp, new Date(now).getDay());
  
  // 解析年表达式
  let yearExp = cronArr[5];
  let nextYear = getNextValidValue(yearExp, new Date(now).getFullYear());
  
  // 计算下一次执行的时间点（注意要考虑到月份和年份的变化）
  let nextDate = new Date(nextYear, nextMonth - 1, nextDay, nextHour, nextMinute);
  while (nextDate.getTime() < now) {
    nextMonth++;
    if (nextMonth > 12) {
      nextMonth = 1;
      nextYear++;
    }
    nextDate.setFullYear(nextYear, nextMonth - 1, nextDay);
  }
  
  return nextDate;
}


	</script>
</html>
